//
//  NSString+Network.h
//  BaseCode
//
//  Created by 曹连华 on 2019/12/4.
//  Copyright © 2019 曹连华. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NetworkQueryPair : NSObject

@property(readwrite, nonatomic, strong) id key;
@property(readwrite, nonatomic, strong) id value;

/**
 *  功能:初始化方法
 */
- (id)initWithKey:(id)aKey value:(id)aValue;

/**
 *  功能:将键值对转化为用"="连接的拼装字符串，并且进行url编码
 */
- (NSString *)URLEncodedStringWithEncoding:(NSStringEncoding)aStringEncoding;

/**
 *  功能:将键值对转化为用"="连接的拼装字符串，不进行url编码
 */
- (NSString *)queryString;

/**
 *  功能:比较方法，根据key进行比较
 */
- (NSComparisonResult)caseInsensitiveCompare:(NetworkQueryPair *)aQueryPair;

@end

@interface NSString (Network)

@property(nonatomic, readonly, nullable) NSString *md5String;

/**
 *  AES解密。
 *  解密流程：Base64 decode --> AES decrypt --> to string (NSUTF8StringEncoding)
 *
 */
- (NSString *)decryptByAESKey:(NSString *)key;

/**
 *  AES加密。
 *  加密流程：AES encrypt --> Base64 encode
 *
 */
- (NSString *)encryptByAESKey:(NSString *)key;

#pragma mark ----------------------------------------- query
/**
 *  功能:将接口参数dictionary转化为用"&"连接的拼装字符串，并进行url编码
 */
+ (NSString *)queryStringFromParameters:(NSDictionary *)aParameters
                               encoding:(NSStringEncoding)aStringEncoding;

+ (NSArray *)queryPairsFromDictionary:(NSDictionary *)dictionary;

@end

NS_ASSUME_NONNULL_END
